package plgdb

import (
	"dgo/MyProj/PrjDBUtils"
	"dgo/goutils/utils"
	"gitee.com/ymofen/gobase/golog"
	"gitee.com/ymofen/supervalue"
)

type PlgDataSourceMgr struct {
	PlgBase
}

func (this *PlgDataSourceMgr) ReloadConf(conf *wrapper.SuperValue) (err error) {
	if conf == nil {
		return
	}

	str := conf.StringByName("datasource", "")
	if len(str) > 0 {
		str = utils.ReplacePlaceholder(str, "$$", "$$")
		json, err := wrapper.NewSVFrom(str, true)
		if err != nil {
			golog.Warnf("解析数据源异常:%s", err.Error())
		} else {
			defer json.Clear()
			PrjDBUtils.LoadDataSourceConfig(json)
		}

	}
	return
}

func CreatePlgDBDataSourceFunc(args ...interface{}) (rval interface{}, err error) {
	obj := &PlgDataSourceMgr{}
	if len(args) > 0 {
		if str, ok := args[0].(string); ok {
			obj.PlugId = str
		}
	}
	rval = obj
	return
}
